package com.logic.AccountControl;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.bean.UserAccountBean;
import com.context.db.DBContext;

public class AdminSearchLogic {


	public List<UserAccountBean> getSearchAccountListByPhoneNumThroughProcedure( String adminID, String phonenum  ){

		Connection conn = null;

		CallableStatement cst = null;

		ResultSet rs = null;

		conn = DBContext.getDBInstance( DBContext.MYSQL ).getDBConnection();

		List<UserAccountBean> mList  = new ArrayList<UserAccountBean>();

		String sql = "{call db.adminsearchuserbyphonenum_proc(?,?)}";

		try {
			cst = conn.prepareCall( sql );

			cst.setString(1, adminID);
			cst.setString(2, phonenum);

			rs = cst.executeQuery();

			while( rs.next() ){
				UserAccountBean bean = new UserAccountBean();

				bean.setId( rs.getInt( "id" ));
				bean.setAccount_type( rs.getString( "account_type" ));
				bean.setAccount_user_type( rs.getString( "account_use_type" ));
				bean.setUserid( rs.getString( "userid" ));
				bean.setEnd_time(rs.getString( "end_time"));
				bean.setAdd_time(rs.getString( "add_time" ));
				bean.setUsed_flag(rs.getString("used_flag"));
				bean.setTelphonenum( rs.getString( "telphonenum" ));
				bean.setBelong( rs.getString( "belongwho" ));
				bean.setPassword( rs.getString( "PASSWORD" ));

				mList.add( bean );

				System.out.println("Search Account List By Procedure===>Account" + rs.getString( "telphonenum" ) + "account added to List");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{

			if( rs != null ){

				try {
					rs.close();

					rs = null;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}


			if( cst != null ){

				try {
					cst.close();

					cst = null;
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
		}

		return mList;

	}
}
